package com.xieyong.mywebsite.model.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.groups.Default;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.URL;


@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User extends BaseEntity {
    @NotNull(groups = {Update.class})
    private Integer id;
    @NotEmpty
    @Pattern(regexp = "^\\S{4,16}$")
    private String username;
    @JsonIgnore
    @Pattern(regexp = "^\\S{4,16}$")
//    把当前对象转换成json字符串的时候，忽略password
    private String password;

    @NotEmpty
    @Pattern(regexp = "^\\S{1,16}$")
    private String nickname;

    private String phone;
    @NotEmpty(groups = {Update.class})
    @Email
    private String email;
//    用户角色，默认为user
    private String role = "USER";

    @URL
    private String avatar;
//  校验分组
    public interface Add extends Default {}
    public interface Update extends Default {}
}
